<template>
	<view class="content">
		<view class="msg">
			<view>
				<text style="margin-right: 10rpx;">租赁次数:</text>
				<text >{{moneyList.length}}</text>
			</view>
			<view>
				<text style="margin-right: 10rpx;">总收益:</text>
				<text style="color: #4CD964;">￥{{all}}</text>
			</view>
		</view>
		<view style="height: 88rpx;"></view>
		<view class="money-list">
			<view class="item" v-for="(i,j) in moneyList" :key=""j>
				<view>
					<text>
						<text style="font-weight: 800;">{{i.name}}</text>
					</text>
					<text style="color: #4CD964;">+￥{{i.money}}</text>
				</view>
				<view>
					<text>
						<text>合同：</text>
						<text>{{i.contract}}</text>
					</text>
					<text style="color: #AAAAAA;">{{i.time}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import api from "../../../../network/index.js"
	export default {
		data() {
			return {
				id: 0,// 这是主机id
				moneyList:[],
			};
		},
		computed:{
			all(){
				let num=0;
				this.moneyList.forEach(res=>{
					num+=res.money
				})
				return num
			},
			share_id(){
				return this.$store.state.user.userInfo.share_id
			}
		},
		methods:{
			// 获取主机关联的订单（device_id）=>(order_id)
			getOrder(){
				const t = this
				api.request({
					url: api.DEVICE_ORDER,
					data:{
						device_id: "=,"+this.id
					}
				}).then(res=>{
					if(res.data.list=="暂无数据")return
					if(res.data.code == "200"){
						res.data.list.data.forEach(i=>{
							t.getShare(i.order_id)
						})
					}else{
						api.error(res)
					}
				}).catch(err=>api.error(err))
			},
			// 便利查询出来的订单-将订单里的主机进行筛选-得到本主机在订单里的数据-在便利主机的股东表-查到自己的股东
			getShare(id){
				const t = this
				api.request({
					url: api.PROJECT_LIST,
					data:{
						id: "=,"+id
					}
				}).then(res=>{
					if(res.data.list=="暂无数据")return
					if(res.data.code == "200"){
						// 拿到项目						
						let data = res.data.list.data[0]
						// console.log(data)
						// 拿到对应的主机
						// console.log(data.ordeDevice)
						let device = data.ordeDevice.filter((i,j)=>i.device.id==t.id)[0]
						// 拿到股东
						// console.log(device)
						let share = device.orderDeviceShare.filter((i,j)=>i.share_id == t.share_id)[0]
						console.log(share)
						// 插入到对象里,项目名称，租赁合同编号，项目创建时间，拿到的钱
						let obj = {
							name: data.project_name,
							contract: data.contractLease.contract_name,
							money: share?share.actual_income:0,
							time: data.create_time.slice(0,7)
						}
						t.moneyList.push(obj)
					}else{
						api.error(res)
					}
				}).catch(err=>api.error(err))
			}
		},
		onLoad(res) {
			this.id = res.id
			this.getOrder()
		}
	}
</script>

<style lang="scss" scoped>
.msg{
	position: fixed;
	left: 0;
	right: 0;
	display: flex;
	justify-content: space-around;
	height: 80rpx;
	line-height: 80rpx;
	background-color: #FFFFFF;
	z-index: 100;
}
.content{
	width: 100vw;
	height: 100vh;
	background-color: #F5F5F5;
}	
.money-list{
	margin: 0 20rpx;
	.item{
		margin: 20rpx 0;
		padding: 20rpx;
		line-height: 48rpx;
		font-size: 28rpx;
		background-color: #FFFFFF;
		box-shadow: 4rpx 4rpx 8rpx #EEEEEE;
		view{
			display: flex;
			justify-content: space-between;
			align-items: center;
		}
	}
}
</style>
